window.checkWechat = function(jsApiList){
    wx.checkJsApi({
        jsApiList, // : ['updateAppMessageShareData', 'updateTimelineShareData'] 需要检测的JS接口列表，所有JS接口列表见附录2,
        success: function(res) {
            showMessage(JSON.stringify(res));
        }
    });
};

window.loadWechat = function(cb){
    if (!window.wx)
        window.appendScript('http://res.wx.qq.com/open/js/jweixin-1.4.0.js');
    if (!window.$)
        window.appendScript(window.rootUrl + '/node_modules/jquery/dist/jquery.min.js');

    $.post('/wechatConfig', {url:window.location.href}, function(data) {
        if (!data.success) {
            showMessage(data.msg);
            return;
        }
        wx.config(data.config);
        wx.ready(function () {
            wx.updateAppMessageShareData({
                title: document.title, // 分享标题
                desc: '', // 分享描述
                link: window.location.href, // 分享链接
                imgUrl: 'http://alljs.top/res/portrait0.png', // 分享图标
                success: ()=> showMessage('已分享给朋友'),
                cancel:  ()=> showMessage('分享取消或失败')
            });
            wx.updateTimelineShareData({
                title: document.title, // 分享标题
                link: window.location.href, // 分享链接
                imgUrl: 'http://alljs.top/res/portrait0.png', // 分享图标
                success: ()=> showMessage('已分享到朋友圈'),
                cancel:  ()=> showMessage('分享取消或失败')
            });
        });
        wx.error(function(res){
            showMessage(res.errMsg);
        })
    });
};